//package com.levy.contronller.javaWeb.findImageTest;
//
//import cn.hutool.core.io.FileUtil;
//import com.levy.contronller.javaWeb.findImageTest.huawei.HWOcrClientAKSK;
//import com.levy.utils.FileTool.TextFileUtils;
//import org.apache.commons.io.IOUtils;
//import org.apache.http.HttpResponse;
//
//import java.util.List;
//
///**
// * Created by levy on 2019/4/26.
// */
//public class HuaWeiFormOcrUtils {
//
//    private static String Httpendpoint = "https://ocr.cn-north-1.myhuaweicloud.com"; //httpendpoint for the service
//    private static String Region = "cn-north-1";   //region name for the service
//    private static String AK = "LBCTYO1ORL4MMHFNJKKT";  //AK from authentication
//    private static String SK = "bttDSDHOLuZvNphftp9siWDizWxbuYWAn0XZIGOT"; //SK from authentication
//    private static String url = "/v1.0/ocr/general-table";
//
//    public static void main(String[] args) {
//
//        long l = System.currentTimeMillis();
//        String imgFileDir = "G://pdf/small//";
//        String saveFileDir = "G://pdf/html//HUAWEI//";
//        List<String> fileNames = FileUtil.listFileNames(imgFileDir);
//        try {
//            for (String s : fileNames) {
//                String pdfbox_image_ = s.replaceAll("pdfbox_image_", "").replaceAll(".png", "");
//                int i = Integer.parseInt(pdfbox_image_);
//                String imgFile = imgFileDir + s;
//                String fileNameWithOutSuff = s.substring(0, s.indexOf(".png")) + ".txt";
//                String saveFile = "";
//                if (i > 52 && i < 59) {
//                    saveFile = saveFileDir + "//firstTable//" + fileNameWithOutSuff;
//                } else if (i > 58) {
//                    saveFile = saveFileDir + "//secondTable//" + fileNameWithOutSuff;
//                } else {
//                    continue;
//                }
////                String type = "json";
//                Thread.sleep(5000);
//                String convertResult = covertFormToJson(imgFile);
//                System.out.println(convertResult);
//                if (!convertResult.contains("error_msg")) {
//                    TextFileUtils.write(saveFile, convertResult, "utf-8");
//                }
//                System.out.println(saveFile + " over");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println("over");
//        System.out.println((System.currentTimeMillis() - l) / 1000);
//    }
//
//
//    private static String covertFormToJson(String img) {
//        try {
//            HWOcrClientAKSK ocrClient = new HWOcrClientAKSK(Httpendpoint, Region, AK, SK);
//            HttpResponse response = ocrClient.requestOcrServiceBase64(url, img);
//            System.out.println(response);
//            String content = IOUtils.toString(response.getEntity().getContent());
//            return content;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//}
